﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EntityLayer;
using DataLayer.EF;
namespace DataLayer.CLASES_DAO
{
    public class clsTB_BcoDestinoDAO
    {

        private BD_TRASNFINTEREntities ContextoDeObjs = new BD_TRASNFINTEREntities();
        public bool Insertar(TB_BcoDestino Obj)
        {
            try
            {
                ContextoDeObjs.AddObject("TB_BcoDestino", Obj);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
        public bool Modificar(TB_BcoDestino obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("TB_BcoDestino", obj);
                ContextoDeObjs.ObjectStateManager.ChangeObjectState(obj, System.Data.EntityState.Modified);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;

            }
            return true;
        }
        public bool Eliminar(TB_BcoDestino obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("TB_BcoDestino", obj);
                ContextoDeObjs.DeleteObject(obj);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
        public List<TB_BcoDestino> listar()
        {

            List<TB_BcoDestino> lista = new List<TB_BcoDestino>();
            try
            {
                var q = from c in ContextoDeObjs.TB_BcoDestino
                        select c;
                lista = q.ToList();

            }
            catch (Exception)
            {
            }
            return lista;
        }

        public int getBancoDestino(string id)
        {
            int estado = 0;
            List<TB_BcoDestino> lista = new List<TB_BcoDestino>();
            try
            {
                var q = from c in ContextoDeObjs.TB_BcoDestino
                        where c.codigoBcoDestino==id
                        select c;
                lista = q.ToList();

                estado = lista.Count;
            }
            catch (Exception)
            {
                return estado = 0;
                throw;
            }

            return estado;
        }
        public List<TB_BcoDestino> getCodigoCorresponsal(string idcodigo)
        {

            List<TB_BcoDestino> lista = new List<TB_BcoDestino>();
            try
            {
                var q = from c in ContextoDeObjs.TB_BcoDestino
                        where c.codigoBcoDestino==idcodigo
                        select c;
                lista = q.ToList();

            }
            catch (Exception)
            {
            }
            return lista;
        }
    }
}
